package password.encoders;

import org.springframework.web.bind.annotation.PostMapping;

import java.util.Base64;

public class LoginControllerDemo {

//    @PostMapping(value = "/logincas")
//    public JSONObject login(HttpServletRequest request) {
//        //cas默认的用户名密码被Base64加密后放到了请求头里
//        String authorization = request.getHeader("authorization");
//        String basic = new String(Base64.getDecoder().decode(authorization.replace("Basic ", "")));
//        String[] split = basic.split(":");
//        SysLoginModel sysLoginModel = new SysLoginModel();
//        sysLoginModel.setUsername(split[0]);
//        sysLoginModel.setPassword(split[1]);
//        //必须返回这个格式，在cas那里才算登录成功
//        JSONObject result = new JSONObject().fluentPut("@class", "org.apereo.cas.authentication.principal.SimplePrincipal")
//                .fluentPut("id", split[0])
//                .fluentPut("attributes", new JSONObject());
//        boolean success = login(sysLoginModel, true).isSuccess();
//        if (success) {
//            return result;
//        } else {
//            return new JSONObject().fluentPut("code", 500).fluentPut("message", "用户名或密码错误");
//        }
//    }

}
